package com.ysu.his.admin.controller;

import com.github.pagehelper.PageInfo;
import com.ysu.his.admin.mapper.DepartmentUserMapper;
import com.ysu.his.admin.service.RoleService;
import com.ysu.his.admin.service.UserService;
import com.ysu.his.dto.UserDto;
import com.ysu.his.entity.user.Role;
import com.ysu.his.entity.user.User;
import com.ysu.his.vo.UserVo;
import com.ysu.his.vo.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/api/admin/user")
public class UserController
{
    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;


    //条件分页查询用户
    @GetMapping(value = "/getUserByPage/{page}/{limit}")
    public Result getUserByPage(@PathVariable("page") Integer page,
                                @PathVariable("limit") Integer limit,
                                UserDto userDto)
    {
        PageInfo<UserVo> pageInfo = userService.getUserByPage(page, limit, userDto);
        return Result.ok(pageInfo);
    }

    @GetMapping(value = "/getAllRole")
    public Result getAllRole()
    {
        List<Role> roleList = roleService.getAllRoles();
        return Result.ok(roleList);
    }

    @PostMapping(value = "/addUser")
    public Result addUser(@RequestBody User user)
    {
        userService.addUser(user);
        return Result.ok(null);
    }

    @GetMapping(value = "/getUserInfoById/{id}")
    public Result getUserInfoById(@PathVariable("id") Long id)
    {
        User user = userService.getUserInfoById(id);
        return Result.ok(user);
    }

    @PutMapping(value = "/updateUserInfo")
    public Result updateUserInfo(@RequestBody User user)
    {
        userService.updateUserInfo(user);
        return Result.ok(null);
    }

    //启用禁用
    @GetMapping(value = "/startOrStop/{userId}/{status}")
    public Result startOrStop(@PathVariable("userId") Long userId,
                              @PathVariable("status") Integer status)
    {
        userService.startOrStop(userId,status);
        return Result.ok(null);
    }

    @DeleteMapping(value = "/deleteUserById/{id}")
    public Result deleteUserById(@PathVariable("id") Long id)
    {
        userService.deleteUserById(id);
        return Result.ok(null);
    }

    @GetMapping(value = "/getAllAvailableDoctor")
    public Result getAllAvailableDoctor()
    {
        List<User> userList = userService.getAllAvailableDoctor();
        return Result.ok(userList);
    }

    @GetMapping(value = "/register/getAllAvailableDoctor")
    public Result getAllAvailableDoctorScheduling()
    {
        List<User> userList  =userService.getAllAvailableDoctorScheduling();
        return Result.ok(userList);
    }

    @GetMapping(value = "/getDoctorByDepartmentId/{departmentId}")
    public Result getDoctorByDepartmentId(@PathVariable("departmentId") Long departmentId)
    {
        List<User> doctorList = userService.getDoctorByDepartmentId(departmentId);

        return Result.ok(doctorList);
    }
}
